<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * array_helper
 *
 * Any array functions to be put in here
 *
 * @author Simon Emms <simon@simonemms.com>
 */

/**
 * Array Keys Exist
 *
 * Does the array_key_exist function for many
 * keys
 *
 * @param array $arrKey
 * @param array $arrArray
 * @return bool
 */
if(!function_exists('array_keys_exist')) {
    function array_keys_exist($arrKey, $arrArray) {
        if(count($arrKey) > 0) {
            foreach($arrKey as $key) {
                if(!array_key_exists($key, $arrArray)) {
                    return false;
                }
            }
        }
        return true;
    }
}







/**
 * Is Multi Array
 *
 * Checks to see if the first element in the
 * array is also an array.  Under most situations,
 * (at least with my coding style) this would
 * mean that it is a multilevel array.
 *
 * @author Simon Emms
 * @param array $array
 * @return bool
 */
if(!function_exists('is_multi_array')) {
    function is_multi_array($array = null) {
        if(is_array($array)) {
            if(is_array(current($array))) {
                /* First element value is array - return true */
                return true;
            }
        }
        return false;
    }
}





/**
 * Sort By Array 
 * 
 * Sorts an array by another array
 * 
 * @param array $arrValues
 * @param array $arrSort
 * @return array
 */
if(!function_exists('sort_by_array')) {
    function sort_by_array(array $arrValues, array $arrSort) {
        $arrReturn = array();
        
        if(count($arrSort) > 0) {
            foreach($arrSort as $key) {
                if(array_key_exists($key, $arrValues)) {
                    $arrReturn[$key] = $arrValues[$key];
                    unset($arrValues[$key]);
                }
            }
        }
        
        /* Put anything back that's not specifically sorted */
        $arrReturn = array_merge($arrReturn, $arrValues);
        
        return $arrReturn;
    }
}





?>